package com.mydemo.utils.dataUtils;

import com.mydemo.entity.Car;
import com.mydemo.utils.dataUtils.addUtils.Add;
import com.mydemo.utils.dataUtils.deleteUtils.Delete;
import com.mydemo.utils.dataUtils.selectUtils.Select;
import com.mydemo.utils.dataUtils.updateUtils.Update;

import java.util.List;


public class DataUtil<T, O extends DataOperation<T>> {
    protected O dataOperation;
    protected Class<T> clazz;
    protected String table;

    public DataUtil(Class<T> clazz, String table) {
        this.clazz = clazz;
        this.table = table;
    }

    // 提供一个执行操作的方法
    public T execute() {
        return dataOperation.execute();
    }

    public Add<T> add(){
        dataOperation = (O) new Add<T>(clazz,table);
        return (Add<T>) dataOperation;
    }

    public Delete<T> delete(){
        dataOperation = (O) new Delete<T>(clazz,table);
        return (Delete<T>) dataOperation;
    }

    public Update<T> update(){
        dataOperation = (O) new Update<T>(clazz,table);
        return (Update<T>) dataOperation;
    }

    public Select<T> select(){
        dataOperation = (O) new Select<T>(clazz,table);
        return (Select<T>) dataOperation;
    }
//    public static void main(String[] args) {
//        DataUtil<Car,?> dataUtil = new DataUtil<>(Car.class,"Car");
////        System.out.println(dataUtil.add().execute());
////        System.out.println(dataUtil.delete().execute());
////        System.out.println(dataUtil.update().execute());
////        System.out.println(dataUtil.select().execute());
//
//        Car car = new Car();
//        car.setId(4);
//        car.setCarBrand("测试品牌");
//        car.setCarModel("测试型号");
////        dataUtil.add().add(car);
////        List<Car> carList = dataUtil.select().select("carBrand","测试品牌");
////        for (Car c :
////                carList) {
////            System.out.println(c.toString());
////        }
////        根据id和根据对象的物理删除方式
////        dataUtil.delete().deleteById(3).execute();
////        dataUtil.delete().deleteById(car).execute();
////        dataUtil.delete().deletePhysically(1);
////        dataUtil.delete().deletePhysically(car);
////        更新操作测试
////        dataUtil.update().updateById(2,5,"seatNum");
////        dataUtil.update().updateObject(car);
////        List<String> testList = new ArrayList<>();
////        testList.add("测试品牌");
////        testList.add("测试型号");
//        List<Car> carList =  dataUtil.select()
////                .not("carBrand","测试品牌1")
//                .like("carBrand","测试")
////                .in("carBrand",testList)
////                .greaterThan("Id",3)
////                .greaterThanOrEqualTo("Id",3)
////                .lessThan("Id",4)
////                .lessThanOrEqualTo("Id",4)
////                .not("Id",4)
////                .selectAll();
////                .where("carBrand","测试品牌")
////                .where("carModel","测试车型1")
////                .end();
//                .endTruly();
////        List<Car> carList = dataUtil.select().where("carModel","测试型号").end();
//        System.out.println("打印");
//        for (Car c:
//             carList) {
//            System.out.println(c.toString());
//            System.out.println(c.getId());
//            System.out.println(c.getIsDeleted());
//        }
//
//
//    }
}